package model;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Date;
import java.util.Set;

public class Customer {
	
	private long id;
	
	private String name;
	
	private String password;
	
	private String phone;
	
	private String email;
	
	private char gender;
	
	private String status;
	
	private int grade;
	
	private String description;
	
	private byte[] avatar;
	
	private Date date;
	
	private Set trade;
	
	private Set favorite;
	
	private Set sell;
	
	private Set addition;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public char getGender() {
		return gender;
	}

	public void setGender(char gender) {
		this.gender = gender;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public int getGrade() {
		return grade;
	}

	public void setGrade(int grade) {
		this.grade = grade;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public byte[] getAvatar() {
		return avatar;
	}

	public void setAvatar(byte[] avatar) {
		this.avatar = avatar;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
	public Set getTrade() {
		return trade;
	}

	public void setTrade(Set trade) {
		this.trade = trade;
	}

	public Set getFavorite() {
		return favorite;
	}

	public void setFavorite(Set favorite) {
		this.favorite = favorite;
	}

	public Set getSell() {
		return sell;
	}

	public void setSell(Set sell) {
		this.sell = sell;
	}

	public Set getAddition() {
		return addition;
	}

	public void setAddition(Set addition) {
		this.addition = addition;
	}

	public Customer(){}
	
	public Customer(Set trades){
		this.trade = trade;
	}
	
	@SuppressWarnings("finally")
	public byte[] imageToByte(String imageName){
		InputStream in = null;
		byte[] buffer = null;
		try{
			in=new FileInputStream(imageName);
			buffer = new byte[in.available()];
			in.read(buffer);
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
		finally{
			return buffer;			
		}
	}
	

	public void byteToImage(String imageName){
		OutputStream out = null;
		try{
			out = new FileOutputStream(imageName);
			out.write(avatar);
		}
		catch(Exception ex){
			ex.printStackTrace();
		}

	}
}
